package it.jack;

import java.io.IOException;
import java.net.MalformedURLException;

import oggetti.PDF;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;

public class HeaderFooter extends PdfPageEventHelper{
	
	private int numpag;
	private String data;
	private int idScheda;
	public HeaderFooter(String data,int idScheda){
		this.numpag=0;
		this.data=data;
		this.idScheda=idScheda;
	}
	
	public void onEndPage(PdfWriter writer, Document document) {
		
        /*Rectangle rect = writer.getBoxSize("art");
        
       ColumnText.showTextAligned(writer.getDirectContent(),
                Element.ALIGN_CENTER, new Phrase("cucu"),
                (rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);*/
		
		PdfPTable table = new PdfPTable(new float[]{1f, 1f, 1f, 4f});
        table.setWidthPercentage(100);
        
        PdfPTable table5 = new PdfPTable(new float[]{4f, 1f});		
        PdfPTable table6 = new PdfPTable(new float[]{3f, 1f});
        PDF.creaFooter(table5, table6);
        try {
			document.add(table);
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	
	public void onStartPage(PdfWriter writer, Document document){
		numpag++;
		try {
			Image image = Image.getInstance("images/logo.png");
			image.scalePercent((float) 50);
			image.setAlignment(1);
			document.add(image);
			document.add(new Paragraph("\n\n"));
		} catch (BadElementException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (MalformedURLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (DocumentException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
         
		PdfPTable table = new PdfPTable(new float[]{1.5f, 1f, 1f, 4f});
        table.setWidthPercentage(100);
        
        PDF.creaHeader(table, data,numpag,idScheda);
        try {
			document.add(table);
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
